package com.vueperson.vueperson.t1.CreationalPattern.SimpleFactoryPattern.Chart;

public class ChartFactory {
    //静态工厂方法
    public static Chart getChart(String type) throws UnsupportedShapeException{


            Chart chart=null;
            if (type.equalsIgnoreCase("histogram")) {
                chart=new HistogramChart();
                System.out.println("初始化设置柱状图");
            }else if (type.equalsIgnoreCase("pie")) {
                chart=new PieChart();
                System.out.println("初始化设置饼状图");
            }else if (type.equalsIgnoreCase("line")) {
                chart=new LineChart();
                System.out.println("初始化设置折线状图");
            }else {
                throw  new UnsupportedShapeException();
            }
        return chart;

    }
}

class  UnsupportedShapeException extends Exception{
    public String toString(){
        return "绘制不支持该几何图形！";
    }
}
